/* 
 * File:   MainGUI.h
 * Author: alrojas
 *
 * Created on 14 de junio de 2014, 8:26
 */

#ifndef _MAINGUI_H
#define	_MAINGUI_H

#include <QGridLayout>
#include <QFormLayout>
#include <QGroupBox>
#include <QMainWindow>
#include <QMenuBar>
#include <QMenu>
#include <QLabel>
#include <QLineEdit>
#include <QSpinBox>
#include <QScrollArea>
#include <QPushButton>
#include <QFileDialog>
#include <QFileInfo>
#include <QString>
#include <QScrollBar>
#include <QMessageBox>
#include <iostream>

#include "opencv2/highgui/highgui.hpp"
#include "OpenCVWrapper.h"
#include "MagickWrapper.h"
#include "Database.h"
#include "Defect.h"
#include "Barcode.h"
#include "EditGUI.h"

using namespace OpenCVWrapper;
using namespace MagickWrapper;
using namespace cv;  
using namespace std;
using namespace Database;
using namespace Defect;
using namespace Barcode;

class MainGUI : public QMainWindow {
    Q_OBJECT
public:
    MainGUI();

private:
    void createObjects();
    void createMenus();
    void createActions();
    void updateActions();
    
    QWidget * centralWid;
    
    EditGUI * editWid;
    
    /* Layouts */    
    QGridLayout * mainLay;
    QFormLayout * infoLay; 
    QGridLayout * resultsLay;
    QBoxLayout * sheetLay; 
    QBoxLayout * parametersLay;
    QFormLayout * erodingLay;
    QFormLayout * defectsDetectionLay;
    
    /* Menus */
    QMenu * fileMenu;
    QMenu * viewMenu;
    QMenu * flatsMenu;
    QMenu * helpMenu;
    
    /* Actions */
    QAction * openAct;
    QAction * saveAct;
    QAction * zoomInAct;
    QAction * zoomOutAct;
    QAction * normalSizeAct;
    QAction * fitToWindowAct;
    QAction * vectorizeAct;
    QAction * loadAct;
    
    /* Groups */
    QGroupBox * infoGro;
    QGroupBox * parametersGro;
    QGroupBox * erodingGro;
    QGroupBox * defectsDetectionGro;
    QGroupBox * resultsGro;
    QGroupBox * sheetGro;
    
    /* LineEdits */
    QLineEdit * nameLEdit;
    QLineEdit * sizeLEdit;
    QLineEdit * idLEdit;
    QLineEdit * defectsLEdit;  
    QLineEdit * defectsAreaLEdit;
    QLineEdit * totalAreaLEdit;
    QLineEdit * usefulAreaLEdit;
    QLineEdit * piecesLEdit;    
    QLineEdit * usedLEdit;
    
    /* SpinBoxes */
    QSpinBox * eKernelSizeLEdit;
    QSpinBox * edThreshLEdit;
    QSpinBox * edKernelSizeLEdit;
    
    /* Scrolls */
    QScrollArea * sheetScr;
    
    /* Labels */
    QLabel * sheetLab;
    
    /* PushButtons */
    QPushButton * startBut;
    QPushButton * editBut;
    
    /* Variables */
    double scaleFactor;
    float free;
    
    QString filename;
    
    QFileInfo fileinfo;
    
    Mat original, src, mask;
    vector < vector < Point > > contours;
    
    /* Support Functions */
    void scaleImage(double factor);
    void adjustScrollBar(QScrollBar * scrollBar, double factor);
    
private slots:
        
    /* File Menu */    
    void open();
    void save();
    
    /* View Menu */
    void zoomIn();
    void zoomOut();
    void normalSize();
    void fitToWindow();
    
    void start();
    void edit();
    
};

#endif	/* _MAINGUI_H */
